package com.itheima.controller;

import com.itheima.anno.Mylog;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Sales;
import com.itheima.pojo.SalesQueryParam;
import com.itheima.service.SalesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 3shy.cn
 * @description SalesController
 */

@Slf4j
@RestController
@RequestMapping("/sale_records")
public class SalesController {

    @Autowired
    private SalesService salesService;

    @GetMapping
    public Result page(SalesQueryParam param) {
        log.info("请求参数： {}", param);
        PageBean pageBean = salesService.page(param);
        return Result.success(pageBean);
    }

    /**
     * 添加
     */
    @Mylog
    @PostMapping
    public Result save(@RequestBody Sales saleRecords) {
        log.info("请求参数emp: {}", saleRecords);
        salesService.save(saleRecords);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @Mylog
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("批量删除记录: ids={} ", ids);
        salesService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 查询回显
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("根据id查询员工的详细信息");
        Sales saleRecords = salesService.getInfo(id);
        return Result.success(saleRecords);
    }

    /**
     * 更新员工信息
     */
    @Mylog
    @PutMapping
    public Result update(@RequestBody Sales sales) {
        log.info("修改订单信息, {}", sales);
        salesService.update(sales);
        return Result.success();
    }


}
